﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CM.Resources.Web.Models
{
    public class FileItem
    {

        /// <summary>
        /// 文件名
        /// </summary>
        public String FileName { get; set; }

        /// <summary>
        /// 相对路径
        /// </summary>
        public String RelativePath { get; set; }

        /// <summary>
        /// 文件大小
        /// </summary>
        public long FileSize { get; set; }
        
        /// <summary>
        /// 可读文件大小
        /// </summary>
        /// <returns></returns>
        public String getReadableSize()
        {
            if (FileSize == 0) {
                return "N/A";
            }
            if (FileSize < 1024)
            {
                return FileSize.ToString();
            }
            if (FileSize < Math.Pow(1024, 2))
            {
                double size = FileSize / 1024;
                return size.ToString("f2") + "KB";
            }
            if (FileSize < Math.Pow(1024, 3))
            {
                double size = FileSize / Math.Pow(1024, 2);
                return size.ToString("f2") + "MB";
            }
            if (FileSize < Math.Pow(1024, 4))
            {
                double size = FileSize / Math.Pow(1024, 3);
                return size.ToString("f2") + "GB";
            }
            if (FileSize < Math.Pow(1024, 5))
            {
                double size = FileSize / Math.Pow(1024, 4);
                return size.ToString("f2") + "TB";
            }
            return FileSize.ToString("f2");
        }

        /// <summary>
        /// 创建日期
        /// </summary>
        public DateTime CreateDate { get; set; }

        /// <summary>
        /// 是否为目录
        /// </summary>
        public Boolean IsDir { get; set; }
    }
}